export function getMenuByRouter(router) {
    let ret = [];
    if (!router) {
        throw new Error("生成菜单，传入路由不可为空！");
    }
    const loop = (node, deep = 0, tmp = {}, curFatherPath = "") => {
        tmp.title = (node.meta && node.meta.title) || node.path;
        tmp.path = deep === 0 ? node.path : `${curFatherPath}/${node.path}`;
        curFatherPath = tmp.path;
        if (deep === 0) {
            ret.push(tmp);
        }
        if (node.children && node.children.length !== 0) {
            tmp.children = [];
            node.children.forEach((item, index) => {
                tmp.children[index] = {};
                return loop(item, deep + 1, tmp.children[index], curFatherPath);
            });
        }
    };

    router.forEach((item) => {
        if (!item.meta.hidden) {
            loop(item);
        }
    });

    return ret;
}
